package com.huak.zookeeper.distributedlock.controller;

import com.huak.zookeeper.distributedlock.service.ProductService;
import com.huak.zookeeper.distributedlock.util.ZkCurator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liuhuan
 * @date 2018/11/17 17:06
 * @description
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private ZkCurator zkCurator;

    @Autowired
    private ProductService productService;


    @GetMapping("/zkAlive")
    public String zkAlive(){
        return zkCurator.isZkAlive()?"连接":"失败";
    }

    @GetMapping("/buy1")
    public String buy1(@RequestParam("id") Integer id,@RequestParam("number") Integer number){
        return productService.updateCountById(id, number)?"下单成功":"下单失败";
    }

    @GetMapping("/buy2")
    public String buy2(@RequestParam("id") Integer id,@RequestParam("number") Integer number){
        return productService.updateCountById(id, number)?"下单成功":"下单失败";
    }

    @GetMapping("/buy3")
    public String buy3(){
        return productService.updateCountById(1)?"下单成功":"下单失败";
    }

    @GetMapping("/buy4")
    public String buy4(){
        return productService.updateCountById(1)?"下单成功":"下单失败";
    }

}
